package outputAdapters;

import inputs.Input;

/**
 * A simple OutputAdapter which scales the input values range to the output range.
 * 
 * @author Dylan James
 *
 */
public class ScaleAdapter extends OutputAdapter{
	
	/**
	 * Constructs a ScaleAdapter without any input.
	 * @param outputRange
	 */
	protected ScaleAdapter(Range outputRange)
	{
		super(outputRange);
	}
	
	/**
	 * Constructs a ScaleAdapter with the given Range and Input
	 * @param outputType The Range to scale the Input to
	 * @param input The data to scale
	 */
	public ScaleAdapter(Range outputRange, Input input)
	{
		super(outputRange, input);
		
	}
	
	protected void Update() {
		int offsetVal = input.getValue() - input.getMin();
		int offsetMax = input.getMax() - input.getMin();
		float val = (float) offsetVal / offsetMax;
		//float val = (float) ((input.getValue() - input.getMin()) / (input.getMax() - input.getMin()));
		value = (int) ((val * (outputRange.getMax() - outputRange.getMin())) + outputRange.getMin());
	}
}
